package com.base.taglib;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import com.lazyzhao.util.pagination.Pagination;

public class PaginationTag extends TagSupport{

	private static final long serialVersionUID = 1L;

	private boolean usecss = true;
	private String style = "";
	private String form = "";
	
	//@SuppressWarnings("unchecked")
	public int doEndTag() throws JspException {
		try {
			HttpServletRequest req = (HttpServletRequest)pageContext.getRequest();
			JspWriter jspOut = pageContext.getOut();
			if(req.getAttribute(Pagination.PARAM_PAGINATION)!=null){
				if("1".equals(style)){
					jspOut.println(((Pagination)(req.getAttribute(Pagination.PARAM_PAGINATION))).getDefautPaginationStyle1(usecss, form));
				}else{
					jspOut.println(((Pagination)(req.getAttribute(Pagination.PARAM_PAGINATION))).getDefautPaginationStyle(usecss, form));
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			throw new JspException(e);
		}
		return EVAL_PAGE;
	}

	public boolean isUsecss() {
		return usecss;
	}

	public void setUsecss(boolean usecss) {
		this.usecss = usecss;
	}

	public String getStyle() {
		return style;
	}

	public void setStyle(String style) {
		this.style = style;
	}

	public String getForm() {
		return form;
	}

	public void setForm(String form) {
		this.form = form;
	}
}
